Nullability

Null Safety

  • Using ?  allows the type to be null.

    let hello: String? = 'hi mom'
    
    • This makes hello  nullable.

Null handling

  • Crashes :

    func hit(enemy: Monster?, with weapon: Weapon) {
        if enemy.isAlive {
            enemy.health -= weapon.damage
        }
    }